package com.ddy.test.kotlintest

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuInflater
import android.widget.ImageView
import android.widget.LinearLayout
import com.ddy.test.kotlintest.utils.CommonUtils
import kotlinx.android.synthetic.main.activity_main.*


class MainTest : AppCompatActivity() {

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        MenuInflater(this).inflate(R.menu.menu, menu)
        return true
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val cardsParent: LinearLayout = findViewById(R.id.cardsParent)

        addCardButton.setOnClickListener {
            val imageView = ImageView(this)
            val uriDefaultCardImage = CommonUtils().getUriFromDrawableResId(this, R.drawable.default_card)

            imageView.setImageURI(uriDefaultCardImage)
            val childCount = cardsParent.childCount
            cardsParent.addView(imageView, childCount-2)

        }
    }


}

